<template>
    <div>
        <van-pull-refresh v-model="tabRefreshing" @refresh="tableViewRefresh">

            <van-list v-model="tableViewLoading" :finished="tableViewFinished" :finished-text='requestFinishedMessage'
                :error-text="requestErrorMessage" @load='tableViewLoadMore' :immediate-check="false"
                style="margin-bottom: 50px;">

                <van-cell v-for="(item, index) in tableViewDataList" :key="index" @click="cellDidSelectMethod(item)">

                    <div
                        v-if="params.code == 'qyzx_qymhcx' || params.code == 'qyzx_qyjqcx' || params.code == 'qyzx_qyfxcx'">

                        <div class="titlefont"> 企业名称：{{item.entName }}</div>
                        <div class="infosfont"> 统一社会信用代码：{{ item.uniscid }}</div>

                        <div v-if="params.code == 'qyzx_qyfxcx'" class="infosfont"> 组织机构代码：{{ item.orgCode }}</div>
                        <div v-else class="infosfont"> 企业分类：{{item.type }}</div>
                    </div>

                    <div v-else-if="params.code == 'qyzx_qyglcx'">
                        <div class="titlefont"> 企业名称：{{ item.searchKey }}</div>
                        <div class="infosfont"> 全网统一项目编码：{{ item.projectCode }}</div>
                    </div>

                    <div v-else>
                        <div class="titlefont">{{ '【' + item.invtype +'】' + item.inv }}</div>
                        <div class="infosfont"> 认缴出资额：{{ item.subconam }}</div>
                        <div class="infosfont"> 出资时间：{{ item.condate }}</div>
                    </div>

                </van-cell>

                <!-- 请求第一页数据时，出现错误或无数据 展示空白提示界面
                请求后续数据时，只做弹窗提示 -->
                <div v-show="showEmptyView" class="text-c">
                    <img width="100px" height="100px" :src="require('@/assets/images/pic_nodata.png')"
                        style="margin: 120px 50px 0" @click="tableViewRefresh()" />
                    <div class="color-b font14" style="margin: 20px 0 0 15px">
                        暂无数据
                    </div>
                </div>

                <div v-show="showErrorView" class="text-c">
                    <img width="100px" height="100px" :src="require('@/assets/images/pic_neterror.png')" alt="获取数据失败"
                        style="margin: 120px 50px 0" @click="tableViewRefresh()" />
                    <div class="color-b font14" style="margin: 20px 0 0 15px">
                        {{ requestErrorMessage }}
                    </div>
                </div>

            </van-list>
        </van-pull-refresh>
    </div>
</template>

<script>

import { requestQYZXListData } from "@/api/dictapi";
import jAccountUtil from '@/assets/js/qyzx_helper';
import { qyzx_qymhcx, qyzx_qyjqcx, qyzx_gqgxcx, qyzx_qyfxcx, qyzx_qyglcx } from '@/assets/js/qyzx_helper'
import jTool from "@/assets/js/jHelper";

import { Toast, Dialog } from "vant";
import { Notify } from "vant";
import { mapGetters } from "vuex";
import moment from 'moment'

export default {
    name: 'sjlistview',
    data() {
        return {

            requestParam: {
                page: 1, rows: 10, size: 10
            },

            requestFinishedMessage: '',
            requestErrorMessage: '',

            tableViewDataList: [],
            tabRefreshing: false,
            tableViewLoading: false,
            tableViewFinished: false,
        }
    },

    props: ['params'],

    computed: {
        ...mapGetters(["user"]),
        ...mapGetters(["userinfo"]),

        showEmptyView() {

            return this.requestParam.page === 1 && this.tableViewDataList.length === 0 && jTool.stringIsEmpty(this.requestErrorMessage);
        },

        showErrorView() {

            return this.requestParam.page === 1 && !jTool.stringIsEmpty(this.requestErrorMessage);
        },


    },

    created() {

        this.tableViewDataList = [];
        // this.tableViewRefresh()
    },

    mounted() {

    },

    activated() {


    },

    methods: {

        // 查询
        requestDataWithFliterCondition(params) {

            Object.assign(this.requestParam, params);
            this.tableViewRefresh();
        },

        tableViewRefresh() {

            this.requestParam.page = 1;

            this.tabRefreshing = true;

            this.tableViewLoading = true;
            this.tableViewFinished = false;
            this.requestListDatas();
        },

        tableViewLoadMore() {

            if (!jTool.stringIsEmpty(this.requestFinishedMessage)) {
                this.tableViewLoading = false
                this.tableViewFinished = true;
            }
            else {

                this.tabRefreshing = false;
                this.requestListDatas();
            }
        },

        requestListDatas() {

            let urlChip = jAccountUtil.getURLWithCode(this.params.code);
            requestQYZXListData(urlChip, this.requestParam)
                .then((result) => {

                    if (!result.data) {
                        this.tableViewFinished = true;
                        this.requestCompletion('result.message');
                        return;
                    }

                    let listdetails = [];
                    if (result.data.data) {
                        listdetails = listdetails.concat(result.data.data);
                    }

                    if (this.requestParam.page == 1) {
                        this.tableViewDataList = listdetails;
                    }
                    else {
                        this.tableViewDataList = this.tableViewDataList.concat(listdetails);
                    }

                    this.requestFinishedMessage = '没有更多数据！';
                    this.tableViewFinished = true;

                    // if (result.data.data.totalPages <= this.requestParam.page) {
                    //     this.requestFinishedMessage = '没有更多数据！';
                    //     this.tableViewFinished = true;
                    // }
                    // else {
                    //     this.requestParam.page++;
                    //     this.requestFinishedMessage = '';
                    // }

                    this.requestCompletion('');
                })
                .catch((error) => {
                    this.tableViewFinished = true;
                    this.requestCompletion('获取数据失败,请稍后重试');
                });
        },


        requestCompletion(error) {

            this.tabRefreshing = false;
            this.tableViewLoading = false

            if (!jTool.stringIsEmpty(error)) {
                this.requestErrorMessage = error;
                Notify({ type: 'warning', message: error })
            }
        },

        timeUtil(value) {
            return moment(value).format('YYYY-MM-DD HH:mm:ss');
        },

        // 
        showCellButton(item) {

            return item.projectHandoverStatus == '售前交接申请已接收'
        },


        

        
        cellDidSelectMethod(value) {

            let params = Object.assign({}, this.params);
            params.formData = value;
            this.$router.push({
                name: "qyzx_content_detail",
                query: params,
            });
        }
    }
}
</script>

<style scoped></style>